﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using thinger.MTHModels;

namespace thinger.MTHDAL
{
    public class SysLogServer
    {
        public DataTable SysLogByTime(string start, string end, string AlarmType)
        {
            string sql = "Select InsertTime,Note,AlarmType,Operator,VarName";

            sql += "from sys_log Where InsertTime between @start and @end";

            List<MySqlParameter> mySqlParameters = new MySqlParameter[]
            {
                new MySqlParameter("@start", start),
                new MySqlParameter("@end", end)

            }.ToList();

            if (AlarmType != null && AlarmType.Length > 0)
            {
                sql += "and AlarmType = @AlarmType";
                mySqlParameters.Add(new MySqlParameter("@AlarmType", AlarmType));
            }

            DataSet dataSet = thinger.MTHHelper.MySqlHelper.GetDataSet(sql, mySqlParameters.ToArray());

            if (dataSet != null && dataSet.Tables.Count > 0)
            {
                DataTable dataTable = dataSet.Tables[0];
            }
            return null;

        }

        public DataTable SysLogAll()
        {
            string sql = "Select InsertTime,Note,AlarmType,Operator,VarName";

            sql += "from sys_log";

            DataSet dataSet = thinger.MTHHelper.MySqlHelper.GetDataSet(sql);

            if (dataSet != null && dataSet.Tables.Count > 0)
            {
                DataTable dataTable = dataSet.Tables[0];
            }
            return null;


        }

        public int addSysLog(SysLog sysLog)
        {
            string sql = "Insert into sys_log(InsertTime,Note,AlarmType,Operator,VarName)";

            sql += "values(@InsertTime,@Note,@AlarmType,@Operator,@VarName)";

            List<MySqlParameter> mySqlParameters = new MySqlParameter[]
            {
                new MySqlParameter("@InsertTime", sysLog.InsertTime),
                new MySqlParameter("@Note", sysLog.Note),
                new MySqlParameter("@AlarmType", sysLog.AlarmType),
                new MySqlParameter("@Operator", sysLog.Operator),
                new MySqlParameter("@VarName", sysLog.VarName)

            }.ToList();
            return thinger.MTHHelper.MySqlHelper.ExecuteSql(sql,mySqlParameters.ToArray());
        }
    }
}
